﻿using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        Console.WriteLine("1000以内的完数有：");

        for (int num = 2; num <= 1000; num++) // 从2开始，因为1不是完数
        {
            List<int> factors = FindFactors(num);
            int sum = SumFactors(factors);

            if (sum == num)
            {
                Console.Write($"{num} = ");
                for (int i = 0; i < factors.Count; i++)
                {
                    Console.Write(factors[i]);
                    if (i < factors.Count - 1)
                        Console.Write(" + ");
                }
                Console.WriteLine();
            }
        }
    }

    // 找出一个数的所有真因子（不包括自身）
    static List<int> FindFactors(int num)
    {
        List<int> factors = new List<int>();

        for (int i = 1; i <= num / 2; i++)
        {
            if (num % i == 0)
                factors.Add(i);
        }

        return factors;
    }

    // 计算因子之和
    static int SumFactors(List<int> factors)
    {
        int sum = 0;
        foreach (int factor in factors)
        {
            sum += factor;
        }
        return sum;
    }
}